Skip to content

feat(perps): extend market categories#8892

Merged
aganglada merged 15 commits into
mainfrom
TAT-3182-core-expand-product-categories
May 27, 2026
Merged

feat(perps): extend market categories#8892
aganglada merged 15 commits into
mainfrom
TAT-3182-core-expand-product-categories

Conversation

@aganglada
Copy link
Copy Markdown
Contributor

@aganglada aganglada commented May 25, 2026

Explanation

Implements TAT-3182 — expands market categories in @metamask/perps-controller with a new enum, static array, and filtering/sorting support on getMarketDataWithPrices.

What changed

New types and constants

  • MarketCategory enum (crypto, stock, pre-ipo, index, etf, commodity, forex) — replaces ad-hoc string literals in HIP3_ASSET_MARKET_TYPES
  • MarketType type alias kept for backward compatibility
  • MARKET_CATEGORIES constant (readonly MarketTypeFilter[]) — 7 ordered category pills, enforced via satisfies; does not include 'all'/'new' sentinels (those are separate UI controls)
  • SortField and SortDirection moved to types/index.ts (re-exported from utils/sortMarkets) to avoid circular imports

New controller method

  • getMarketCategories() — returns MARKET_CATEGORIES so clients can enumerate pills at runtime without hardcoding the list

Extended params

  • GetMarketsParams gains four optional fields: categories, sortBy, direction, limit
  • PerpsProvider.getMarketDataWithPrices() accepts the same fields via Pick<GetMarketsParams, ...>

Filtering / sorting / pagination (in MarketDataService, not PerpsController)

  • matchesCategory() — pure function mapping MarketTypeFilter | 'watchlist' to a PerpsMarketData predicate
  • applyMarketFilters() — applies category filter (OR logic) → sort → slice in order
  • MarketDataService.getMarketDataWithPrices() — new service method with tracing and error handling that fetches from the provider then applies filters

Breaking change

  • 'equity' market type replaced by 'stock', 'pre-ipo', 'index', 'etf'

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Breaking MarketType change (equity → stock/pre-ipo/index/etf) requires consumer updates; market list behavior now depends on post-fetch filtering in MarketDataService, which can affect UI lists and preload if params differ from before.

Overview
Extends perps market discovery with granular HIP-3 categories and server-side-style post-processing on priced market lists.

MarketCategory / MARKET_CATEGORIES / getMarketCategories() give clients a stable ordered list of seven UI category pills (crypto, stocks, pre-ipo, indices, etfs, commodities, forex), excluding all / new sentinels.

Breaking: MarketType no longer uses 'equity'; assets are classified as 'stock', 'pre-ipo', 'index', or 'etf' (and related types). HIP3_ASSET_MARKET_TYPES is expanded and remapped accordingly (e.g. indices/ETFs split out from former equity entries, URNM → ETF).

getMarketDataWithPrices now accepts GetMarketDataWithPricesParams (categories, sortBy, direction, limit, excludeSymbols, standalone) and routes through MarketDataService with matchesCategory / applyMarketFilters (OR category match → exclude symbols → sort → limit) instead of calling the provider directly. SortField / SortDirection move to package types and are re-exported from the root.

Messenger types add PerpsController:getMarketCategories; tests cover filtering, sorting, limits, and config classification.

Reviewed by Cursor Bugbot for commit d708462. Bugbot is set up for automated code reviews on this repo. Configure here.

@aganglada aganglada self-assigned this May 25, 2026
@aganglada aganglada requested review from a team as code owners May 25, 2026 14:03
@aganglada aganglada temporarily deployed to default-branch May 25, 2026 14:03 — with GitHub Actions Inactive
Comment thread packages/perps-controller/src/index.ts Outdated
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Category filtering currently accepts valid inputs that return empty or incomplete results. Watchlist filtering needs implementation or removal from the accepted API, and explicit crypto categorization should be honored.

Comment thread packages/perps-controller/src/services/MarketDataService.ts Outdated
Comment thread packages/perps-controller/src/services/MarketDataService.ts Outdated
Comment thread packages/perps-controller/src/services/MarketDataService.ts
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more API-surface issue: GetMarketsParams now exposes filters that getMarkets does not apply.

Comment thread packages/perps-controller/src/types/index.ts
Comment thread packages/perps-controller/src/types/index.ts Outdated
Comment thread packages/perps-controller/src/types/index.ts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 46c4f27. Configure here.

Comment thread packages/perps-controller/src/services/MarketDataService.ts Outdated
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One TypeScript API compatibility issue remains.

Comment thread packages/perps-controller/src/types/index.ts Outdated
@aganglada aganglada enabled auto-merge May 26, 2026 15:29
Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review — see comment above for full details.

@abretonc7s abretonc7s dismissed their stale review May 27, 2026 12:43

Re-posting with correct content

@abretonc7s
Copy link
Copy Markdown
Contributor

Automated Review — PR #8892

BETA — Automated review from the farmslot pipeline.

Recommendation REQUEST_CHANGES
Runner claude / opus
Tier standard

Summary

  1. JSDoc says "includes 'all' and 'new'" but method excludes themPerpsController.ts:3984 and PerpsController-method-action-types.ts:588 both claim getMarketCategories() returns arrays including 'all' and 'new'. The actual return value (MARKET_CATEGORIES) explicitly excludes those sentinels per types/index.ts:106. Fix the JSDoc.

  2. SortField/SortDirection re-exported from two paths — Defined in types/index.ts, re-exported from utils/sortMarkets.ts:7, and both paths reach src/index.ts. Pick one canonical source and drop the other re-export to avoid consumer confusion.

Full review details

Validation

  • Build: no new errors (pre-existing TS6305 from unbuilt deps)
  • Tests: 59 suites, 1754 passed, 0 failed
  • Downstream clones not available; API analysis shows no breakage for additive changes; 'equity' removal is documented with consumer PRs prepared
---

No video evidence recorded.

Copy link
Copy Markdown
Contributor

@abretonc7s abretonc7s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review — see comment above for full details.

@aganglada aganglada added this pull request to the merge queue May 27, 2026
Merged via the queue into main with commit d17a912 May 27, 2026
370 checks passed
@aganglada aganglada deleted the TAT-3182-core-expand-product-categories branch May 27, 2026 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants